package com.zr.d_c.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.d_c.model.Customer;
import com.zr.d_c.model.User;
import com.zr.d_c.service.UserInfoService;
import com.zr.d_c.service.UserService;
import com.zr.d_c.serviceimpl.UserInfoServiceImpl;
import com.zr.d_c.serviceimpl.UserServiceImpl;
/**
 * 顾客注册
 * @author Administrator
 *
 */
public class CustomerRegisterController extends HttpServlet{
	UserService userservice = new UserServiceImpl();
	UserInfoService userinfoservice = new UserInfoServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String uname = req.getParameter("uname");
		String upsw = req.getParameter("upsw");
		String cname = req.getParameter("cname");
		String cage = req.getParameter("cage");
		String csex = req.getParameter("csex");
		String cphone = req.getParameter("cphone");
		String cemail = req.getParameter("cemail");
		String ccreatetime = req.getParameter("ccreatetime");
		PrintWriter pw = resp.getWriter();
		if(userservice.getUserByUname(uname)==1){
			pw.write("0");
		}else{
			if(userservice.addUser(uname, upsw)==1){
				User u = userservice.getUserByUnameAndUpsw(uname, upsw);
				int uid = u.getUid();
				Customer c = new Customer(cname, cage, csex, cphone, cemail, ccreatetime, uid);
				if(userinfoservice.addCustomerInfo(c)==1){
					pw.write("1");
				};
			}
		}
		pw.close();
	}
}
